Return to doc.sitecore.com

Documentation

1.  Description

Xml Importer is a shared source tool for importing data from XML files into the Sitecore database. Source XML files must be converted into Sitecore compatible format.

The module functionality can be logically split into two parts:

After the package installation, the module settings should be changed to match the physical paths of the local file system. All the administration settings are placed under the /sitecore/system/Modules/XmlImporter/Profiles Item as shown in the image below:

/upload/sdn5/shared library/modules/xml importer/xml_importer_01.jpg

2.  Installation Guide

The XmlImporter tool  is distributed as a standard Sitecore package. Thus, to start using it, you should install the package. Please refer to the Installing Modules and Packages article if you are not familiar with the standard Sitecore Packager tool. 

3.  User Manual

After the package installation, some settings need to be tuned before using the module. These settings are: 

  1. XsltPath:
    physical path to the converter.xslt stylesheet used to convert raw xml data. It is installed with the package into the /sources folder of your solution root.
     
  2. SourcePath:
    physical path to the root folder of data hierarchy. A sample is installed with the package into the /sources/home folder of your solution root. 
      
  3. DebugFolder:
    physical path to the debug folder, where the temporary xml files in Sitecore compatible format are placed. The empty /sources/debug folder is installed with the package.

/upload/sdn5/shared library/modules/xml importer/xml_importer_02.jpg  

After correct settings are provided and the changes are saved, the module is ready for use.

Enter the following URL in your browser:
http://<yourdomain>/sources/testimport.html

This is a simple GUI to debug the module. Press the Import button and wait for the importing process to complete. It takes approximately 3 minutes with the test data installed with the package. The “Done!” message will appear after the data is successfully imported:

 /upload/sdn5/shared library/modules/xml importer/xml_importer_03.png

Now that the data is transferred, open the Content Editor to ensure that there is no data loss. You should be able to see the imported content with the tree structure reflecting the physical file locations.

Note: Each kind of XML data requires its own XSLT stylesheet to be transformed into a format recognized by Sitecore. Read more about it in the Architectural notes section.

4.  Architectural Notes

As it was mentioned in the description section, the module can be logically divided into two parts.

4.1.  Converting Data to Sitecore Compatible Format

Once you have the raw XML data with a certain structure retrieved from external sources, you need to create a specific XSLT stylesheet, which will transform your data into Sitecore compatible format.

Note: The term “Sitecore compatible” means that this format provides all the information necessary to create a regular Sitecore item: ID, name, template. All the fields should be put as nesting elements and contain such attributes as name and type.

The XmlImporter module creates temporary XML files in Sitecore compatible format, one for each source file. They are placed in the debug folder (defined by the “DebugFolder” setting).

If you want to customize the module for accepting specific raw data, do the following:

4.2.  Converting to Sitecore Content Items

After performing the initial transformation, the module imports the data to Sitecore assuming that it has the following format:

<item name="…" id="…" template="…">
     <field name="…" type="…"> …  </field>
     <field name="…" type="…"> …  </field>
     …
     <field name="…" type="…"> …  </field>
     <item …> // child items
     </item>
</item>

Note: Templates which Sitecore Items will be based on (specified by the values of the template attribute above) should already be present in the database.

The temporary file may contain nested <item> elements; it depends on your raw input data. In this case, the appropriate child Items will be created in the Sitecore content tree.

Note: The physical structure of your input data will be reflected in the Sitecore content tree structure. Keep in mind this fact when planning to import the content.